package com.tarena.tocketmq.consumer;

import com.tarena.tocketmq.pojo.po.TeduUser;
import com.tarena.tocketmq.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@RocketMQMessageListener(topic = "topic01",consumerGroup = "test-consumer-group")
public class UserConsumerListener implements RocketMQListener<TeduUser> {
    @Autowired
    private UserService userService;

    @Override
    public void onMessage(TeduUser teduUser) {
        String result = null;
        try {
            result = userService.printUser(teduUser);
            log.info("打印成功：{}",result);
        } catch (RuntimeException e) {
            log.error("打印失败：{}",e.getMessage());
        }
        log.info("打印完毕：{}",result);
    }
}
